﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
using EnvironmentManagerSystem.Utility;


namespace EnvironmentManagerSystem.HuanTongRoleManage
{
    public partial class RoleManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return; if (!IsPostBack)
            {
                if (!Convert.ToBoolean(Session["gly"]))
                {
                    gvRole.Columns[2].Visible = false;
                    btnReBind.Visible = false;
                    Button1.Visible = false;
                    Button2.Visible = false;
                }
                BindGv();
            }
        }

        #region BindGv(x)
        private void BindGv()
        {
            gvRole.DataSource = Role.GetLists();
            gvRole.DataBind();
        }
        protected void gvRole_RowEditing(object sender, GridViewEditEventArgs e)
        {
            gvRole.EditIndex = e.NewEditIndex;
            BindGv();
        }
        protected void gvRole_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            gvRole.EditIndex = -1;
            BindGv();
        }
        protected void gvRole_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvRole.PageIndex = e.NewPageIndex;
        }
        protected void gvRole_PageIndexChanged(object sender, EventArgs e)
        {
            BindGv();
        }
        #endregion

        #region 删除(x)
        protected void gvRole_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int ID = (int)gvRole.DataKeys[e.RowIndex].Value;
            if (!Role.DeleteRole(ID))
                Jscript.Alert("删除失败！", this);
            BindGv();
        }
        #endregion

        #region 更改角色名(x)
        protected void gvRole_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            RoleData model = new RoleData();
            model.ID = Convert.ToInt32(gvRole.DataKeys[e.RowIndex].Value);
            model.RoleName = ((TextBox)gvRole.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
            if (!Role.UpdateRole(model))
                Jscript.Alert("更新失败！", this);
            else
                Jscript.Alert("更新成功！", this);
            gvRole.EditIndex = -1;
            BindGv();
        }
        #endregion

        #region btnReBind_Click(x)
        protected void btnReBind_Click(object sender, EventArgs e)
        {
            BindGv();
        }
        #endregion

        #region 鼠标滑动(x)
        protected void gvRole_DataBound(object sender, EventArgs e)
        {
            OfficeHelper.HelpDv(gvRole);
        }
        #endregion
    }
}
